package com.facotry.service.Impl;

import com.facotry.entity.worker;
import com.facotry.mapper.workerMapper;
import com.facotry.service.workerService;
import com.facotry.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author 崔瑜航
 * @date 2024/7/24
 * @desc
 */
@Service
public class workerServiceImpl implements workerService {
    @Autowired
    private com.facotry.mapper.workerMapper workerMapper;
    @Override
    public List<worker> findAllWorker(HashMap<String, String> map) {
        return workerMapper.findAllWorker(map);
    }

    @Override
    public boolean addworker(worker worker) {
        worker.setwCreateTime(new Date());

        return workerMapper.addworker(worker);
    }

    @Override
    public boolean updateworker(worker worker) {
        return workerMapper.updateworker(worker);
    }

    @Override
    public boolean del(int wId) {
        return workerMapper.del(wId);
    }

    @Override
    public boolean delBatch(List<String> ids) {
        return workerMapper.delBatch(ids);
    }

    @Override
    public R getNum() {

        List<Object> values = new ArrayList<>();
        List<Map<String,Object>> resultMap =workerMapper.getNum();
                resultMap.forEach(stateMap ->{
            if (stateMap.get("状态").equals("启用")){
                values.add(Integer.parseInt(String.valueOf(stateMap.get("val"))));
            }else if (stateMap.get("状态").equals("请假")){
                values.add(Integer.parseInt(String.valueOf(stateMap.get("val"))));
            }
        });
        HashMap<Object, List<Object >>  map = new HashMap<>();
        map.put("category", Arrays.asList("启用","请假"));
        map.put("value",values);
        /**
         * {
         *     category: [启用,请假],
         *     value: [6,3]
         * }
         */

        return R.ok(map);
    }

    @Override
    public void saveBatch(ArrayList<worker> list) {
        workerMapper.saveBatch(list);
    }
}
